#!/bin/sh
# Creates soft links between vim canonical_config dirs/files listed below and
# n/vim dirs/files listed further below. Checks that they don't yet exist and
# that the canonical configs do exist.

# Define where canonical configs are

vim_config_dir="$HOME/my-configs/vim"
vim_config_file="$vim_config_dir/vimrc"

# Check that canonical configs exist

if test -d "$vim_config_dir"
then
  echo "Trace: $vim_config_dir exists, as it should."
else
  echo "Error: $vim_config_dir does not exist"
  exit 1
fi

if test -e "$vim_config_file"
then
  echo "Trace: $vim_config_file exists, as it should."
else
  echo "Error: $vim_config_file does not exist"
  exit 1
fi

# Define where soft links to configs should be

vim_dir="$HOME/.vim"
vim_file="$HOME/.vimrc"
nvim_dir="$HOME/.config/nvim"
nvim_file="$nvim_dir/init.vim"

# Echo and execute soft-linking commands
# Will print error messages if any of the targets already exist

print_and_exec()
{
  echo "Trace: $@"
  eval "$@"
}

print_and_exec ln -s "$vim_config_dir" "$vim_dir"
print_and_exec ln -s "$vim_config_dir" "$nvim_dir"
print_and_exec ln -s "$vim_config_file" "$vim_file"
print_and_exec ln -s "$vim_config_file" "$nvim_file"
